package com.automobile.backstage.service.impl;


import com.automobile.backstage.dao.AnnounceDao;
import com.automobile.backstage.domain.Announce;
import com.automobile.backstage.service.AnnounceService;
import com.github.pagehelper.PageHelper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.stereotype.Service;

import java.util.List;

@Service("announceService")
public class AnnounceServiceImpl implements AnnounceService {

    @Autowired
    @Qualifier("announceDao")
    private AnnounceDao announceDao;


    @Override
    public List<Announce> findUserPaste(int userId) {
        List<Announce> announces = announceDao.findAnnounceByUserId(userId);
        return announces;
    }

    @Override
    public Announce findAnnounceById(int announceId) {
        Announce announce = announceDao.findAnnounceById(announceId);
        return announce;
    }

    public int save(Announce announce) {
        // TODO Auto-generated method stub
        return announceDao.save(announce);
    }

    public void update(Announce announce) {
        // TODO Auto-generated method stub
        announceDao.update(announce);
    }

    @Override
    public void updateStatus(String status, Integer id) {
        announceDao.updateStatus(status,id);
    }

    public void delete(List<Integer> ids) {
        for(Integer id : ids)
            announceDao.delete(id);
    }

    @Override
    public List<Announce> findAll(Integer page,Integer size) throws Exception {
        PageHelper.startPage(page,size);
        return announceDao.findAll();
    }
}
